<?php /*a:2:{s:84:"/www/wwwroot/survey.sdwanyue.com/public/themes/admin_simpleboot3/admin/ask/edit.html";i:1618294278;s:83:"/www/wwwroot/survey.sdwanyue.com/public/themes/admin_simpleboot3/public/header.html";i:1610676092;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- HTML5 shim for IE8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->


    <link href="/themes/admin_simpleboot3/public/assets/themes/<?php echo cmf_get_admin_style(); ?>/bootstrap.min.css" rel="stylesheet">
    <link href="/themes/admin_simpleboot3/public/assets/simpleboot3/css/simplebootadmin.css" rel="stylesheet">
    <link href="/static/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        form .input-order {
            margin-bottom: 0px;
            padding: 0 2px;
            width: 42px;
            font-size: 12px;
        }

        form .input-order:focus {
            outline: none;
        }

        .table-actions {
            margin-top: 5px;
            margin-bottom: 5px;
            padding: 0px;
        }

        .table-list {
            margin-bottom: 0px;
        }

        .form-required {
            color: red;
        }
    </style>
    <script type="text/javascript">
        //全局变量
        var GV = {
            ROOT: "/",
            WEB_ROOT: "/",
            JS_ROOT: "static/js/",
            APP: '<?php echo app('request')->module(); ?>'/*当前应用名*/
        };
    </script>
    <script src="/themes/admin_simpleboot3/public/assets/js/jquery-1.10.2.min.js"></script>
    <script src="/static/js/wind.js"></script>
    <script src="/themes/admin_simpleboot3/public/assets/js/bootstrap.min.js"></script>
    <script>
        Wind.css('artDialog');
        Wind.css('layer');
        $(function () {
            $("[data-toggle='tooltip']").tooltip({
                container:'body',
                html:true,
            });
            $("li.dropdown").hover(function () {
                $(this).addClass("open");
            }, function () {
                $(this).removeClass("open");
            });
        });
    </script>
    <?php if(APP_DEBUG): ?>
        <style>
            #think_page_trace_open {
                z-index: 9999;
            }
        </style>
    <?php endif; ?>

<style type="text/css">
    .option-parent {
        position: relative;
    }

    .moveanswer-btn {
        position: absolute;
        top: 7px;
        right: -5%;
    }

    .span_add{
        display: inline-block;
        margin-top: 20px;
        margin-bottom: 5px;
        width: 104px;
        height: 34px;
        line-height: 34px;
        text-align: center;
        color: #38DAA6;
        font-size: 14px;
        border: 1px solid #38DAA6;
        border-radius: 4px;
        cursor: pointer;
    }

</style>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li><a href="<?php echo url('ask/index',['listid'=>$listid,'status'=>$status]); ?>">问卷题目</a></li>
        <li class="active"><a href="<?php echo url('ask/edit',['listid'=>$listid]); ?>">编辑</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="<?php echo url('ask/editPost'); ?>">
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">题干<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" id="input-name" name="title" value="<?php echo $result['title']; ?>">
            </div>
        </div>
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">选项个数(正整数)<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10">
                <input type="text" disabled="disabled" class="form-control" id="input-count" value="<?php echo $result['count_option']; ?>" name="count_option" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
            </div>
        </div>
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">最多可选(正整数)<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" id="input-name" value="<?php echo $result['count_max']; ?>" name="count_max" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
            </div>
        </div>
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">最少可选(正整数)<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" id="input-name" value="<?php echo $result['count_min']; ?>" name="count_min" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
            </div>
        </div>
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">选项<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10" id="options">
                <?php if(is_array($result['option']) || $result['option'] instanceof \think\Collection || $result['option'] instanceof \think\Paginator): $i = 0; $__LIST__ = $result['option'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                    <div class="option-parent">
                        <input type="text" class="form-control" id="input-name" name="option[]" value="<?php echo $vo; ?>" style="margin-bottom:3px">

                        <?php if(isset($result['thumbs_json'][$key])): ?>
                            <input type="hidden" name="thumb<?php echo $key; ?>" id="thumbnail<?php echo $key; ?>"  value="<?php echo $result['thumbs_json'][$key]; ?>">
                            <a href="javascript:uploadOneImage('图片上传','#thumbnail<?php echo $key; ?>');">
                                <?php if(empty($result['thumbs_json'][$key])): ?>
                                    <img src="/themes/admin_simpleboot3/public/assets/images/default-thumbnail.png"
                                         id="thumbnail<?php echo $key; ?>-preview" width="135" style="cursor: hand"/>
                                    <?php else: ?>
                                    <img src="<?php echo cmf_get_image_preview_url($result['thumbs_json'][$key]); ?>" id="thumbnail<?php echo $key; ?>-preview"
                                         width="135" style="cursor: hand"/>
                                <?php endif; ?>
                            </a>

                        <?php endif; ?>
                        <a class="moveanswer-btn btn btn-xs btn-danger js-ajax-dialog-btn"
                           href="<?php echo url('ask/moveanswer',array('index'=> $key, 'id' => $result['id'])); ?>"
                           data-msg="确认删除此项?">删除</a>
                        <input type="hidden" name="option_key[]" value="<?php echo $key; ?>">
                    </div>
                <?php endforeach; endif; else: echo "" ;endif; ?>
            </div>
        </div>

        <div class="form-group add_bd">
            <label for="input-name" style="margin-right: 15px;" class="col-sm-2 control-label"><span class="form-required"></span></label>
            <div class="col-md-6 col-sm-10 span_add add_1_1">添加选项</div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="hidden" class="form-control" name="id" value="<?php echo $result['id']; ?>">
                <?php if($status == 0 || $status == 2): ?>
                    <button type="submit" class="btn btn-primary js-ajax-submit"><?php echo lang('EDIT'); ?></button>
                <?php endif; ?>
                <a class="btn btn-default" href="<?php echo url('ask/index',array('listid'=>$listid,'status'=>$status)); ?>"><?php echo lang('BACK'); ?></a>
            </div>
        </div>
    </form>
</div>
<script src="/static/js/admin.js"></script>

<script type="text/javascript">


    $(function () {
        $("#input-count").on("change",function(){
            html='';
            var count = $(this).val();
            for(i=0;i<count;i++){
                html+='<input type="text" class="form-control" id="input-name" name="option[]" style="margin-bottom:3px">';
            }
            $("#options").html(html);
        });
    });

    $('.add_1_1').on('click',function (){
        let _that=$(this);
        // 最后一个选项元素的id值
        let ids = [];
        $('input[name^="option_key"]').each(function(index,element){	//index下标 element 当前选中的元素
            ids.push($(this).val());//压入对象数组
        });
        let newId = parseInt(ids[ids.length - 1]) + 1;

        let html1 = '<div class="option-parent"><input type="text" class="form-control" id="input-name" name="option[]" value="" style="margin-bottom:3px">';
        html1 += '<input type="hidden" name="thumb' + newId + '" id="thumbnail' + newId + '"  value="">';
        html1 += '<a href="javascript:uploadOneImage(\'图片上传\',\'#thumbnail' + newId + '\');">';
        html1 += '<img src="/themes/admin_simpleboot3/public/assets/images/default-thumbnail.png" id="thumbnail' + newId + '-preview" width="135" style="cursor: hand"/>';
        html1 += '</a>';
        html1 += '<a class="moveanswer-btn btn btn-xs btn-danger moveanswer-new-btn' + newId + '" onclick="moveAnswer(' + newId + ')" href="javascript:;"';
        html1 += 'data-msg="确认删除此项?">删除</a>';
        html1 += ' <input type="hidden" name="option_key[]" value="' + newId + '">';
        html1 += '</div>';

        $('#options').append(html1);

    });


    //移除追加的选项
    function moveAnswer(newId) {
        let id = '<?php echo $result['id']; ?>';
        $(".moveanswer-new-btn" + newId).parents(".option-parent").remove();

    }




</script>
</body>
</html>